using System;
using System.Collections;
using System.Collections.Generic;
using PALib;
using UnityEngine;
public class GameEntry : AbstractGameEntry
{
    public GameObject gb;
    public GameObject audio;
    private IObjectPool<Transform> coinPool;
    #region  注册类实现
    // 使用字典存储所有注册的类实例，按类型分类

    #endregion 取消注册类
    // Start is called before the first frame update
    void Start()
    {
        RegisterSystem(audio.GetComponent<AudioSystem>());
        RegisterSystem(new ObjectPool());
        RegisterSystem(new EventSystem());

        GetSystem<EventSystem>().RegisterEvent<int>(GameEventType.LevelCompleted, Test);
        GetSystem<EventSystem>().RegisterEvent<int, string>(GameEventType.ItemCollected, Test2);
        GetSystem<EventSystem>().RegisterEvent<int, string, bool>(GameEventType.EnemyKilled, Back);
        coinPool = GetSystem<ObjectPool>().InitPool<Transform>("CoinS", gb);
    }

    private List<Transform> tes = new List<Transform>();
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            //eventSystem.TriggerEvent(GameEventType.LevelCompleted, 100);
            GetSystem<AudioSystem>().PlayMusic("Bg1");
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            GetSystem<EventSystem>().TriggerEvent(GameEventType.ItemCollected, 100, "tom");
            GetSystem<AudioSystem>().CrossFadeMusic("Bg2");
        }
        if (Input.GetKeyDown(KeyCode.C))
        {
            bool tt = GetSystem<EventSystem>().TriggerFuncEvent<int, string, bool>(GameEventType.EnemyKilled, 10, "sss");
            Debug.Log("=========================" + tt);
        }
        if (Input.GetKeyDown(KeyCode.P))
        {
            tes.Add(coinPool.Get());
        }
        if (Input.GetKeyDown(KeyCode.O))
        {
            //coinPool.Release();
            for (int i = tes.Count -1; i >=0; i--)
            {
                coinPool.Release(tes[i]);
            }
        }
    }
    private void Test(int index)
    {
        Debug.Log("=================" + index);
    }
    private void Test2(int index, string name)
    {
        Debug.Log(name + "=================" + index);
    }
    private bool Back(int index, string name)
    {
        Debug.Log(name + "=================" + index);
        return index > 50;
    }
}
